Skip to content

Warn when the installation ID can't be saved; add require_persisted - #7

Merged
catsika merged 1 commit into
mainfrom
fix/installation-id-not-saved
Nov 13, 2026
Merged

catsika merged 1 commit into
mainfrom
fix/installation-id-not-saved

Conversation

@catsika

@catsika catsika commented Nov 12, 2026

Copy link
Copy Markdown
Member

Problem

identity.get_or_create_installation_id() swallowed write errors and returned an unsaved ID. On a read-only disk, in a sandbox, or without permission to write ~/.keymint, every launch generated a different ID, so the same machine used another activation slot each time, and the app got no signal.

Change (backwards compatible)

  • Default unchanged. The function still returns an ID and never raises because of a failed save. It now emits one InstallationIdWarning (a RuntimeWarning subclass) per process naming the storage path.
  • Opt-in strict mode. New keyword-only argument require_persisted=False. With True it raises InstallationIdError when the ID can't be saved and read back, or an existing file can't be read. InstallationIdError subclasses OSError (so existing except OSError handlers still catch it) and has path.
  • After writing, the value is read back to confirm it persisted.
  • Return type unchanged (str).
  • InstallationIdError and InstallationIdWarning are exported from keymint.
  • Docstring, README ("When the installation ID can't be saved") and CHANGELOG (Unreleased) describe the default, the warning and the strict option, and recommend require_persisted=True for desktop apps that activate devices.

No version bump.

Tests

New tests/test_identity.py:

  • saves normally and returns the same ID next time (default and strict);
  • an existing readable file is reused;
  • unwritable path in default mode returns an ID and warns exactly once;
  • strict mode raises InstallationIdError with the path;
  • read-only directory via chmod (skipped on Windows or as root);
  • strict mode raises when the value doesn't read back.

pytest -q tests: 97 passed. ruff check .: clean.

…ire_persisted

get_or_create_installation_id swallowed write errors and returned an
unsaved ID, so every launch on a read-only or sandboxed disk produced a new
ID and used another activation slot, with no signal to the app.

- Default behaviour is unchanged: an unsaved ID is still returned, but one
  InstallationIdWarning (a RuntimeWarning subclass) is now emitted per
  process.
- New keyword-only require_persisted=False. With True it raises
  InstallationIdError (an OSError subclass, with path) when the ID can't be
  saved and read back, or an existing file can't be read.
- The saved value is read back to confirm it persisted.
- InstallationIdError and InstallationIdWarning are exported from keymint.
- Tests, README and CHANGELOG.
@catsika
catsika merged commit 0279274 into main Nov 13, 2026
2 checks passed
@catsika
catsika deleted the fix/installation-id-not-saved branch November 13, 2026 01:12
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant